import pygame
from .. import tools, setup, constants
from ..components import info


class LoadScreen:
    def start(self, game_info):
        self.game_info = game_info
        self.setup_player()
        self.info = info.Info("load_screen", self.game_info)
        self.finished = False
        self.next = "level"
        self.timer = 0
        self.duration = 2000

    def setup_player(self):
        self.player_image = tools.get_image(setup.graphs["mario_bros"], 178, 32, 12, 16, (0, 0, 0), constants.PLAYER_MULTI)

    def update(self, surface, keys):
        self.draw(surface)
        if self.timer == 0:
            self.timer = pygame.time.get_ticks()
        if pygame.time.get_ticks() - self.timer > self.duration:
            self.finished = True
            self.timer = 0

    def draw(self, surface):
        surface.fill((0, 0, 0))
        self.info.draw(surface)
        surface.blit(self.player_image, (300, 270))


# 复用LoadScreen界面
class GameOver(LoadScreen):
    def start(self, game_info):
        self.game_info =game_info
        self.finished = False
        self.next = "main_menu"
        self.duration = 4000
        self.timer = 0
        self.info = info.Info("game_over", self.game_info)

    def draw(self, surface):
        surface.fill((0, 0, 0))
        self.info.draw(surface)
